<@admin.header title="系统菜单管理列表">
<script language="JavaScript" src="${base}/resources/scripts/jquery/jquery-1.4.2.js">
</script>
<@common.zTree/>
<script type="text/javascript">
    $(document).ready(function(){
        App.ns('Brand');
        
        
        Brand.form = new App.common.Form({
            base: '${base}/brand'
        });
        
        
        Brand.search = function(){
            $('#searchForm').submit();
        }
        
        Brand.del = function(ids){
            Brand.form.deleteRecord(ids);
        }
    });
	
	var menuTree;
	var maxLevel = 2;
	
    function onDrop(treeId, orgins, target, moveType){
        if (!orgins || orgins.length < 1) {
            alert('没有选中结点');
            return false;
        }
        var orgin = orgins[0];
        var msg = "";
        var pid = "";
		var orderNo = orgin["orderno"]||0;
        if (target) {
			var tp = target.getParentNode();
			if(tp){
				console.log(tp)
			}
            if (target.id == orgin.pid) {
                alert('已经在此菜单下');
                return false;
            }
            pid = target.id;
            msg = "确认将菜单 <" + orgin.name + "> 移动到菜单 <" + target.name + "> 下? 确定将完成移动";
			
        }
        else {
            msg = "确认将菜单 <" + orgin.name + "> 作为一级菜单?";
        }
        if (confirm(msg)) {
            $.ajax({
                type: "post",
                data: {
                    "id": orgin.id,
                    "pid": pid
                },
                url: '${base}/car/brand/changeParent.do',
                success: function(data){
                    if(data&&data.success){
						App.Msg.alert("操作成功!");
					}
                }
            });
            return true;
        }
        else {
            return false;
        }
    }
	/**
	 * @deprecated
	 * @param {Object} id
	 */
    function addChildNode(id){
		if(menuTree){
			var node = menuTree.getNodeByTId("menuTree_"+id);
			if(node&&node.level>0){
				App.toast.error("无法为二级品牌添加子品牌(限定只允许添加两级品牌)");
				return;
			}
		}
		//window.location.href="add.do?pid="+id;
	}
	
    function onRemove(treeId, treeNode){
        if (confirm('确认删除这个品牌吗?\n(注意，将要删除的品牌下的汽车将全部变为无品牌，需要人工重新设定品牌，请慎重操作！！)')) {
            var url = "${base}/car/brand/delete.do";
            $.ajax({
                type: "post",
                data: {
                    'ids': treeNode.id
                },
                url: url,
                success: function(data){
                    if (data && data.success) {
                        App.Msg.alert(data.message);
                    }
                    window.location.reload();
                }
            });
            
        }
        else {
            return false;
        }
    }
    
    
    var setting = {
        edit: {
            enable: true,
            showRemoveBtn: true,
            showRenameBtn: false
        },
        callback: {
            beforeDrop: onDrop,
            beforeRemove: onRemove
        },
        view: {
            addDiyDom: function(treeId, treeNode){
                var obj = $("#" + treeNode.tId + "_a");
                var editStr = "<span style='font-size:12px;'>";
				if(treeNode.level<(maxLevel-1)){
	                editStr += "<a href='add.do?pid=" + treeNode.id + "'>添加子品牌</a>";
				}
                editStr += "<a href='edit.do?id=" + treeNode.id + "'>修改</a>";
                editStr += "</span>";
                obj.after(editStr);
            }
        },
        async: {
            enable: true,
            rootKey: 'root',
            url: "tree.do"
        }
    };
    
    function GetData(){
		var searchText = $('#searchText').val();
		var url = "${base}/car/brand/tree.do";
        $.ajax({
            type: "post",
            data: {
                'searchText': searchText
            },
            url: url,
            success: function(data){
                if (data && data.success) {
					 menuTree = $.fn.zTree.init($("#menuTree"), setting,data.root);
					 menuTree.expandAll(true);
                }
            }
        });
    }
	
    
    $(document).ready(function(){
    
       GetData();
    });
</script>
</@admin.header>
<body>
    <div class="place">
        <span>位置：</span>
        <ul class="placeul">
            <li>
                <a href="#">首页</a>
            </li>
            <li>
                <a href="list.do">系统菜单管理管理</a>
            </li>
            <li>
                <a href="#">系统菜单管理列表</a>
            </li>
        </ul>
    </div>
    <div class="rightinfo">
        <!--默认查询表单-->
        <div class="tools">
                <input type="hidden" name="pageNo" value="1"/>
                <ul class="toolbar">
                    <li class="click">
                        <a href="add.do"><span><img src="${base}/resources/images/t01.png" /></span>添加</a>
                    </li>
                    <li style="padding:0 0">
                        <span style="margin:0px 5px">关键字</span>
                        <input id="searchText" name="searchText" type="text" class="dfinput" onkeypress="if(event.keyCode==13){$(this).blur();GetData();return false;}" style="width:160px;"/>&nbsp;
                    </li>
                    <li>
                        <a href="javascript:GetData()"><span><img src="${base}/resources/images/search24.png" /></span>查找</a>
                    </li>
                </ul>
        </div>
    </div><!-- Definition of context menu -->
    <div id="treeDiv" style="width:350px;margin:20px 20px;border:1px dashed #000;float:left;">
        <span id="msg"></span>
        <br/>
        <br/>
        <ul id="menuTree" class="ztree">
        </ul>
        <br/>
        <br/>
        <br/>
    </div>
</body>
</html>
